﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ariregistri_toimik_Response", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(AriregistriToimikResponse))]
    public class AriregistriToimikResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IAriregistriToimikResponse clazz;
        
        public AriregistriToimikResponseSerializer(IAriregistriToimikResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ariregistri_kood");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.AriregistriKood))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("dokumendid");
            if (clazz.Dokumendid!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("ariregistri_toimik_dokument", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Dokumendid.Count);
                for (int x = 0; ((clazz.Dokumendid != null) 
                            && (x < clazz.Dokumendid.Count)); x = (x + 1)) {
                    if (clazz.Dokumendid[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaDokumendid = this.GetMetaData(clazz.Dokumendid[x]);
                        Writer.WriteTypeAttribute(metaDokumendid.TypeQualifiedName.Namespace, metaDokumendid.TypeQualifiedName.Name);
                        metaDokumendid.NewSerializer(clazz.Dokumendid[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Dokumendid");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("otsused");
            if (clazz.Otsused!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("ariregistri_toimik_otsus", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Otsused.Count);
                for (int x = 0; ((clazz.Otsused != null) 
                            && (x < clazz.Otsused.Count)); x = (x + 1)) {
                    if (clazz.Otsused[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaOtsused = this.GetMetaData(clazz.Otsused[x]);
                        Writer.WriteTypeAttribute(metaOtsused.TypeQualifiedName.Namespace, metaOtsused.TypeQualifiedName.Name);
                        metaOtsused.NewSerializer(clazz.Otsused[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Otsused");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("hoiatused");
            if (clazz.Hoiatused!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("ariregistri_toimik_hoiatus", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Hoiatused.Count);
                for (int x = 0; ((clazz.Hoiatused != null) 
                            && (x < clazz.Hoiatused.Count)); x = (x + 1)) {
                    if (clazz.Hoiatused[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaHoiatused = this.GetMetaData(clazz.Hoiatused[x]);
                        Writer.WriteTypeAttribute(metaHoiatused.TypeQualifiedName.Namespace, metaHoiatused.TypeQualifiedName.Name);
                        metaHoiatused.NewSerializer(clazz.Hoiatused[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Hoiatused");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ariregistri_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ariregistri_toimik_Response>ariregistri_kood");
                }
                clazz.AriregistriKood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("ariregistri_kood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_Response>ariregistri_kood", Reader.LocalName);
            }
            if (Reader.LocalName=="dokumendid") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ariregistri_toimik_Response>dokumendid");
                }
                clazz.Dokumendid = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAriregistriToimikDokument>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("dokumendid");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ariregistri_toimik_dokumendid>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaDokumendid = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAriregistriToimikDokument>(Reader, "ariregistri_toimik_dokument", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAriregistriToimikDokument item = metaDokumendid.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAriregistriToimikDokument>();
                        clazz.Dokumendid.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaDokumendid.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_Response>dokumendid", Reader.LocalName);
            }
            if (Reader.LocalName=="otsused") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ariregistri_toimik_Response>otsused");
                }
                clazz.Otsused = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAriregistriToimikOtsus>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("otsused");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ariregistri_toimik_otsused>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaOtsused = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAriregistriToimikOtsus>(Reader, "ariregistri_toimik_otsus", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAriregistriToimikOtsus item = metaOtsused.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAriregistriToimikOtsus>();
                        clazz.Otsused.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaOtsused.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_Response>otsused", Reader.LocalName);
            }
            if (Reader.LocalName=="hoiatused") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ariregistri_toimik_Response>hoiatused");
                }
                clazz.Hoiatused = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAriregistriToimikHoiatus>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("hoiatused");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ariregistri_toimik_hoiatused>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaHoiatused = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAriregistriToimikHoiatus>(Reader, "ariregistri_toimik_hoiatus", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAriregistriToimikHoiatus item = metaHoiatused.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAriregistriToimikHoiatus>();
                        clazz.Hoiatused.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaHoiatused.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ariregistri_toimik_Response>hoiatused", Reader.LocalName);
            }
        }
    }
}
